package pl.edu.pw.elka.tinyrepo.common;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;


public class HTTPHeaderTestClass {
   public static void main(String[] args) throws IOException {
      Request r = new Request("GET /test HTTP/1.1");
      System.out.println("przed wyslaniem naglowka.");
      r.addHeader(HTTPHeaderType.CONTENT_TYPE, "application/octet-stream");
      r.addHeader(HTTPHeaderType.CONTENT_LENGTH, "170");
      r.write(System.out);
      r = new Request();
      InputStream in = null;
      try {
         in = new FileInputStream(new File("/home/nieznany/Pulpit/BD2A18_ERD.PNG"));
//         r.setRequestLine(Message.readInputLine(in));
//         r.read(in);
         
      } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      catch (IOException e) {
         // TODO: handle exception
      }

      System.out.println("Sciezka "+r.getPath());
      System.out.println("metoda "+r.getMethod());
      System.out.println("naglowki"+r.headers);
      System.out.println("Po naglowku");
      File file = new File("/home/nieznany/Pulpit/kopia.png");
      file.createNewFile();
      FileOutputStream fo = new FileOutputStream(file);
      
      int b; 
      while((b = in.read()) != -1) {
         fo.write((byte)b);
      }
      fo.close();
      in.close();
     }
}
